#include "stdafx.h"

#ifdef __APPLE__
int main()
#else
int _tmain(int argc, _TCHAR* argv[])
#endif
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "zevil 2D");
    sf::RectangleShape r(Vector2f(3,3));
    r.setPosition(1,1);
    r.setFillColor(sf::Color::Yellow);
    
    game_machine mach;
    
    //bar.frame.setPosition(10,10);
    sf::Clock clock;
//    Text text;
//    text.setString("qwhfasFSVKGDSF!@#$%^&*()_+{}\"|:>?<[]'\\;./,");
//    Font font;
//    font.loadFromFile("ProFontWindows.ttf");
//    text.setFont(font);
//    text.setCharacterSize(12);
//    text.setPosition(20,20);
    window.setFramerateLimit(30);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)// || event.type==sf::Event::KeyPressed)
                window.close();
            if(event.type == sf::Event::KeyPressed)// || event.type == sf::Event::KeyReleased)
            {
                //mach.console.push_text("you pushed"+TO_STR(event.key.code));
                switch(event.key.code)
                {
                case Keyboard::Num1:
                        mach.cast_cmd(1,0,2);
                    break;
                case Keyboard::Num2:
                        mach.cast_cmd(1,1,2);
                    break;
                case Keyboard::Num3:
                        mach.cast_cmd(1,2,2);
                    break;
                case Keyboard::Num4:
                        mach.cast_cmd(1,3,2);
                    break;
                case Keyboard::Num5:
                        mach.cast_cmd(1,4,2);
                    break;
                case Keyboard::Escape:
                    window.close();
                    break;
                }
            }
        }

        mach.timeSinceLastFrame = clock.getElapsedTime().asSeconds();

        mach.update();

        clock.restart();
        
        window.clear();
        
        FOR(LINES) window.draw(mach.console.lines[i]);
        window.draw(mach.bar.frame);
        window.draw(mach.bar.progress);
            
        window.display();
    }

    //system("PAUSE");
    return 0;
}
